home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n03 / ucrasm.exe / SOURCE.EXE / LTOA.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-10-12  |  1.9 KB  |  117 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8.         extrn    sl_malloc:far
  9. ;
  10. ; Release 2.0 modifications 9/22/91, R. Hyde
  11. ; Created three versions of each routine: LTOA, LTOA2, and LTOAm
  12. ;
  13. ; LTOA-    converts the value in DX:AX to a string.  ES:DI points at the target
  14. ;    location.
  15. ;
  16. ; LTOA2-Like the routine above, except it does not preserve DI.  Leaves DI
  17. ;    pointing at the terminating zero byte.
  18. ;
  19.         public    sl_ltoa
  20. sl_ltoa        proc    far
  21.         push    di
  22.         call    far ptr sl_ltoa2
  23.         pop    di
  24.         ret
  25. sl_ltoa        endp
  26. ;
  27.         public    sl_ltoa2
  28. sl_ltoa2    proc    far
  29.         push    ax
  30.         push    bx
  31.         push    cx
  32.         push    dx
  33. ;
  34.         cmp    dx, 0
  35.         jge    Doit
  36.         mov    byte ptr es:[di], '-'
  37.         inc    di
  38.         neg    dx
  39.         neg    ax
  40.         sbb    dx, 0
  41. ;
  42. DoIt:        call    puti4
  43.         mov    byte ptr es:[di], 0
  44.         clc                ;Needed by sl_ltoam
  45.         pop    dx
  46.         pop    cx
  47.         pop    bx
  48.         pop    ax
  49.         ret
  50. sl_ltoa2    endp
  51. ;
  52. ;
  53. ;
  54. ; ULTOA converts the unsigned dword value in DX:AX to a string.
  55. ; ULTOA does not preserve DI, rather, it leaves DI pointing at the 0 byte.
  56. ;
  57.         public    sl_ultoa
  58. sl_ultoa    proc    far
  59.         push    di
  60.         call    far ptr sl_ultoa2
  61.         pop    di
  62.         ret
  63. sl_ultoa    endp
  64. ;
  65. ;
  66.         public    sl_ultoa2
  67. sl_ultoa2    proc    far
  68.         push    ax
  69.         push    bx
  70.         push    cx
  71.         push    dx
  72.         call    PutI4
  73.         clc
  74.         pop    dx
  75.         pop    cx
  76.         pop    bx
  77.         pop    ax
  78.         ret
  79. sl_ultoa2    endp
  80. ;
  81. ;
  82. ;
  83. ; PutI4- Recursive routine to actually print the value in DX:AX as an integer.
  84. ;
  85. Puti4        proc    near
  86.         call    Div10
  87.         cmp    ax, dx        ;See if dx:ax=0
  88.         jnz    NotDone
  89.         or    ax, ax
  90.         jz    Done
  91. NotDone:    push    bx
  92.         call    Puti4
  93.         pop    bx
  94. Done:        mov    al, bl
  95.         or    al, '0'
  96.         mov    es:[di], al
  97.         inc    di
  98.         ret
  99. PutI4         endp
  100. ;
  101. ; Div10- Divides DX:AX by 10 leaving the remainder in BL and the quotient
  102. ;     in DX:AX.
  103. ;
  104. Div10        proc    near
  105.         mov    cx, 10
  106.         mov    bx, ax
  107.         xchg    ax, dx
  108.         xor    dx, dx
  109.         div    cx
  110.         xchg    bx, ax
  111.         div    cx
  112.         xchg    dx, bx
  113.         ret
  114. Div10        endp
  115. stdlib        ends
  116.         end
  117.